package com.right.health.app.ui.main.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.right.health.app.R;
import com.right.health.app.app.App;
import com.right.health.app.base.BasePresenterFragment;
import com.right.health.app.common.DataCommon;
import com.right.health.app.hyphenate.ui.ChatActivity;
import com.right.health.app.ui.advisory.FindDoctorByQrcodeActivity;
import com.right.health.app.ui.advisory.MyDoctorActivity;
import com.right.health.app.ui.main.adapter.AdvisoyAdapter;

/*
 * Created by hopeliao on 2019-09-23
 * 咨询
 *
 */
public class AdvisoyFragment extends BasePresenterFragment implements View.OnClickListener {

     private AdvisoyAdapter mAdapter;

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle, String s) {
        return layoutInflater.inflate(R.layout.advisoy, viewGroup, false);
    }

    @Override
    public void findView() {
        findViewById(R.id.ib_add).setOnClickListener(this);

        ListView listView = (ListView) findViewById(R.id.listview);
        mAdapter = new AdvisoyAdapter(getActivity());
        listView.setAdapter(mAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String toUserId = "";
                if(App.getInstance().getUser().mobilephone.equals("13444444444")) {
                    toUserId ="u191225215538876103214919521274";
                } else {
                    toUserId ="u191225220644418607441887847131";
                }
                Bundle bundle = new Bundle();
                bundle.putString("userId", toUserId);
                startIntent(ChatActivity.class, bundle);
            }
        });

        findViewById(R.id.ib_my_doctor).setOnClickListener(this);
    }

    @Override
    public void initialize() {
        mAdapter.setDataSource(DataCommon.getTestDataSource());
    }

    @Override
    public void onClick(View v) {
        if(!isAdded()) {
            return;
        }
        if(v.getId() == R.id.ib_my_doctor) {
            startIntent(MyDoctorActivity.class);
        } else if(v.getId() == R.id.ib_add) {
            startIntent(FindDoctorByQrcodeActivity.class);
        }
    }
}
